package com.housekeeping.housekeeping.administrator.adminsinformation.controller;

import com.housekeeping.housekeeping.administrator.adminsinformation.service.search.SearchService;
import com.housekeeping.housekeeping.administrator.adminsinformation.service.search.SearchServiceImpl;
import com.housekeeping.housekeeping.administrator.entity.AdminsInformation;
import com.housekeeping.housekeeping.administrator.utils.ResponseEntity;
import com.housekeeping.housekeeping.administrator.utils.ResponseUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/information/search")
public class SearchController extends HttpServlet {
    private SearchService service=new SearchServiceImpl();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置请求字符集
        req.setCharacterEncoding("utf-8");
        //设置响应字符集
        resp.setContentType("text/html;charset=utf-8");
        String keyword=new String(req.getParameter("keyword").getBytes("ISO-8859-1"),"utf-8");
        List<AdminsInformation> list = service.search(keyword);
        ResponseEntity<List<AdminsInformation>> entity=null;
        if (list.size()>0) {
                entity = ResponseEntity.success(list);

        }else {
            entity=ResponseEntity.error();
        }
        ResponseUtils.responseJson(resp,entity);
    }
}
